# -*- coding: utf-8 -*-
"""
Created on Mon Apr 02 21:03:44 2018
@author: Fsl
"""
import shutil
import os
import pandas as pd


# 这个库复制文件比较省事

def objFileName():
    '''
    生成文件名列表
    :return:
    '''
    local_file_name_list = r'G:\KeTi\OCT\ImageSets\Main\test.txt'
    # 指定名单
    obj_name_list = []
    for i in open(local_file_name_list, 'r'):
        obj_name_list.append(i.replace('\n', ''))
    return obj_name_list


def copy_img():
    '''
    复制、重命名、粘贴文件
    :return:
    '''
    local_img_name = r'G:\KeTi\OCT\JPEGImages'
    # 指定要复制的图片路径
    path = r'G:\KeTi\OCT\data'
    # 指定存放图片的目录
    for i in objFileName():
        new_obj_name = i + '.jpg'
        shutil.copy(local_img_name + '/' + new_obj_name, path + '/' + new_obj_name)

def partition_img(csv_path,img_src_dir,img_dst_dir):
    lines = pd.read_csv(csv_path).values

    for line in lines:
        file_name = line[0]
        folder_name = line[1]
        src_path = img_src_dir+'/' + file_name
        dst_dir = img_dst_dir+'/' + folder_name
        if not os.path.exists(dst_dir):
            os.makedirs(dst_dir)
        dst_path = dst_dir +'/'+ file_name
        shutil.copy(src_path,dst_path)
        print(file_name)

if __name__ == '__main__':
    csv_path = 'G:/data_copy/LWSCID-S/LWSCID-S_new.CSV'
    img_src_dir = 'G:\data_copy\img'
    img_dst_dir = 'G:\data_copy\img_cla'
    partition_img(csv_path,img_src_dir,img_dst_dir)